<script setup>
import WelcomeItem from './WelcomeItem.vue'
import DocumentationIcon from './icons/IconDocumentation.vue'
import subAppInfo from '@/constant'
import microApp from '@micro-zoe/micro-app'
import { useRouter } from 'vue-router';

const router = useRouter()

const handleRouteToSubApp = () => {
  router.push(`${subAppInfo.devServer.base}`)
  // setTimeout(() => {
  //   microApp.setData('child/vite', { path: '/' })
  // }, 1000);
}

if (window[`eventCenterFor${subAppInfo.name}`]) {
  // 返回子应用的data数据
  // const childData = microApp.getData(appName)
  microApp.addDataListener(subAppInfo.name, function(data) {
    console.log('---[data from sub app by microApp.addDataListener]---', data)
  })
}

</script>

<template>
  <WelcomeItem>
    <template #icon>
      <DocumentationIcon />
    </template>
    <template #heading>sub app</template>
    <span
      :style="{ cursor: 'pointer', color: '#33aa66' }"
      @click="handleRouteToSubApp"
    >child vite app</span>
  </WelcomeItem>
</template>
